package com.zhiyi.app.controller;

import com.zhiyi.app.entity.DevUser;
import com.zhiyi.app.service.DevUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author shichenyang
 */
@Controller
@RequestMapping("/dev")
public class DevUserController {

    @Autowired
    private DevUserService userService;

    /**
     * 登录
     * @return
     */
    @PostMapping("/login")
    public String login(DevUser user, HttpSession session){
        user= userService.login(user);
        if (user!=null){
            //如果存在，保存用户数据，跳转回开发者界面
            session.setAttribute("user",user);
            return "redirect:/app/list";
        }
        return "devlogin";
    }

    /**
     * 注销
     * @return
     */
    @GetMapping("/logout")
    public String logout(HttpSession session){
        session.removeAttribute("user");
        return "devlogin";
    }
}
